//警告：这是自动生成的代码，不要手动去修改.
//使用 wrapCLI 工具生成，工具版本为 <0.1.6>.

using System;
using System.Runtime.InteropServices;
namespace TTEngine {
    public class Framework {
        private const string dllFile = @"..\..\..\..\..\..\..\dotenv\out\debug\Native.Core.dll";
        public struct handle_void { public UInt64 ptr; }
//自定义类型 
        public delegate void deleOnWinRender(int winid);
        unsafe delegate void deleOnLog(char* log);
        public delegate void deleOnLog_safe(string log);
        public delegate void deleOnMouseMotion(int winid,int x,int y,bool press);
        public delegate void deleOnMouseButton(int winid,int x,int y,byte buttonid,bool press,byte click);
        public delegate void deleOnMouseWheel(int winid,int sx,int sy,bool flipped);
        public delegate void deleOnKey(int winid,int scancode,int keycode,bool press,byte repeat);
        unsafe delegate void deleOnInput(int winid,char* input);
        public delegate void deleOnInput_safe(int winid,string input);
        unsafe delegate void deleOnInputEdit(int winid,char* input,int pos,int length);
        public delegate void deleOnInputEdit_safe(int winid,string input,int pos,int length);
        public delegate void deleOnTouchEvent(int winid,int touchid,int fingerid,float x,float y,float dx,float dy,float pressure);
        public struct handle_Target { public UInt64 ptr; }
        public struct handle_Texture { public UInt64 ptr; }
        public struct handle_Material { public UInt64 ptr; }
        public struct handle_Mesh { public UInt64 ptr; }
        public struct XYWH{
            public int x;
            public int y;
            public int w;
            public int h;
        }
        public struct Vector4{
            public float x;
            public float y;
            public float z;
            public float w;
        }
        public enum UniformType{
            Sampler ,
            End ,
            Vec4 ,
            Mat3 ,
            Mat4 ,
            Count ,
        }
        public enum VertexFormat{
            Nothing ,
            Pos ,
            Pos_Color0 ,
            Pos_UV0_Color0 ,
            Pos_UV0_UV1_Color0_Color1 ,
            Pos_UV0_UV1_UV2_Color0_Color1_Color2 ,
            Pos_UV0_UV1_UV2_UV3_Color0_Color1_Color2_Color3 ,
        }
//函数 
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        unsafe static extern void APP_SetLogger(deleOnLog logger);
        public static void APP_SetLogger_safe(deleOnLog_safe logger){
            unsafe { 
                deleOnLog _logger = (log)=> { 
                 string _log = new string(log);
                    logger(_log);
                };
                APP_SetLogger(_logger);
            }
        }
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int App_MainLoop(string title,Action onInit,Action onUpdate,deleOnWinRender onWinRender,Action onExit);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int Editor_MainLoop(string title,handle_void windowHandler);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern int GetFocusWindowID();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern int GetMousePos(int* x,int* y);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Events_RegMouse(deleOnMouseMotion onMouseMotion,deleOnMouseButton onMouseButton,deleOnMouseWheel onMouseWheel);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        unsafe static extern void Events_RegKey(deleOnKey onKeyPress,deleOnInput OnInput,deleOnInputEdit OnInputEdit,Action OnKeyInputKeymapChange);
        public static void Events_RegKey_safe(deleOnKey onKeyPress,deleOnInput_safe OnInput,deleOnInputEdit_safe OnInputEdit,Action OnKeyInputKeymapChange){
            unsafe { 
                deleOnInput _OnInput = (winid ,input)=> { 
                 string _input = new string(input);
                    OnInput(winid ,_input);
                };
                deleOnInputEdit _OnInputEdit = (winid ,input ,pos ,length)=> { 
                 string _input = new string(input);
                    OnInputEdit(winid ,_input ,pos ,length);
                };
                Events_RegKey(onKeyPress ,_OnInput ,_OnInputEdit ,OnKeyInputKeymapChange);
            }
        }
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Events_RegTouch(deleOnTouchEvent onTouchMotion,deleOnTouchEvent onTouchDown,deleOnTouchEvent onTouchUp);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern int Window_GetMainWinID();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int Window_Create(string title,bool borderless);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Window_Exists(int winid);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Window_SetPos(int winid,int x,int y,int w,int h);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Window_GetPos(int winid,ref int x,ref int y,ref int w,ref int h);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Window_Destory(int winid);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Target Target_Create(uint width,uint height);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Target_Destory(handle_Target handle);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Target_Reset(handle_Target handle,int width,int height);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void MainScreen_Reset(int width,int height);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_BeginRender(handle_void winHandle,int width,int height);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_EndRender();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_Clear(uint color,bool withColor,bool withDepth);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_Draw(handle_Material mat,handle_Mesh mesh);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_Begin();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Frame_Flush();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern handle_Texture Texture_LoadFromFile(string filename);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern handle_Texture Texture_LoadFromMem(byte* mem,uint size);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Texture Texture_Create(uint width,uint height);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Texture_Upload(handle_Texture texture,XYWH xywh,byte* mem,int size);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Texture_Destory(handle_Texture handle);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Material Material_CreateDefault();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Material Material_CreateDefaultOutline();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Material Material_CreateDefaultTexture();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern handle_Material Material_Create(string shadername);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Material_Destory(handle_Material material);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern int Material_GetUniformCount(handle_Material material);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        unsafe static extern char* Material_GetUniformName(handle_Material material,int index,string namebuf,int bufsize);
        public static string Material_GetUniformName_safe(handle_Material material,int index,string namebuf,int bufsize){
            unsafe { 
                var __retVal__ = Material_GetUniformName(material ,index ,namebuf ,bufsize);
                return new string(__retVal__);
            }
        }
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern ulong Material_GetUniformNameHash(handle_Material material,int index);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern UniformType Material_GetUniformType(handle_Material material,int index);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Material_SetTexture(handle_Material material,int uniformID,handle_Texture texture);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Material_SetVec4(handle_Material material,int uniformID,Vector4 value);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Mesh Mesh_CreateSample();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern handle_Mesh Mesh_Create(VertexFormat format,int vertexCount,int triCount,byte* memVB = null,ushort* memIB = null);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Mesh_Destory(handle_Mesh handle);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern int Mesh_GetVertexStride(handle_Mesh handle);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern handle_Mesh MeshDynamic_Create(VertexFormat format,int vertexCount,int triCount);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void MeshDynamic_UploadVertex(handle_Mesh mesh,int VertexStart,int VertexCount,byte* mem);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void MeshDynamic_UploadIndex(handle_Mesh mesh,int IndexStart,int IndexCount,ushort* indexdata);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public static extern void Matrix_Test();
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_SetViewProj(float* view,float* proj);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_SetModel(float* model);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_GenIdentity(float* matresult);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_GenOrtho(float* matresult,float left,float right,float bottom,float top,float near,float far);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_GenProj(float* matresult,float fov,float asp,float near,float far);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_GenViewLookAt(float* matresult,float* eys,float* to);
        [DllImport(dllFile , CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void Matrix_GenRotate(float* matresult,float x,float y,float z);
    }
}
